﻿using MaterialSkin.Controls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AIOUpload
{
    public partial class AIOUpload : MaterialForm
    {
        public AIOUpload()
        {
            windowDisplay(false);
            InitializeComponent();
        }


        /// <summary>
        /// 自定义方法：窗体的隐藏与显示
        /// </summary>
        /// <param name="display"></param>
        private void windowDisplay(bool display)
        {
            if (display)
            {
                this.WindowState = FormWindowState.Normal; // 窗口常规化
                this.ShowInTaskbar = true; // 显示在任务栏
            }
            else
            {
                this.WindowState = FormWindowState.Minimized; // 窗口最小化
                this.ShowInTaskbar = false; // 不显示在任务栏
            }

        }

        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            windowDisplay(true);
        }

        private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
        {
            // 需要将事件转换成鼠标事件
            MouseEventArgs mouseEvent = (MouseEventArgs)e;
            if (mouseEvent.Button == MouseButtons.Left) // 点击左键才弹出
            {
                windowDisplay(true);
            }
        }
        //首次出现
        private void AIOUpload_Shown(object sender, EventArgs e)
        {
            notifyIcon1.ShowBalloonTip(300, "提示", "数据上传程序已经运行！", ToolTipIcon.Info);
            notifyIcon1.Visible = true;
        }

        /// <summary>
        /// 向文本框写日志
        /// </summary>
        /// <param name="log">日志</param>
        void WriteLog(string log)
        {
            if (materialMultiLineTextBoxLog.InvokeRequired)
            {
                materialMultiLineTextBoxLog.Invoke(new Action(() =>
                {
                    materialMultiLineTextBoxLog.AppendText(log);
                }));
            }
            else
            {
                materialMultiLineTextBoxLog.AppendText(log);
            }

        }
    }
}
